﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "WindowButton.h"
#include "settingsdialog.h"

#include <QCefView.h>
#include <QMainWindow>
#include <ShellAudio.h>

QT_BEGIN_NAMESPACE
namespace QWK {
class WidgetWindowAgent;
class StyleAgent;
class WindowBar;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    enum Theme {
        Dark,
        Light,
    };
    Q_ENUM(Theme)
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
public slots:
    void notifyPlayerMsg(MediaPlayer::PLAYER_STATE playerState, QString taskId, int sessionId, QString msg);
    void showDev();
protected:
    void initServices();
    void installWindowAagent();
    void initCefView();
    void loadStyleSheet(Theme theme);
    bool event(QEvent *event) override;
    void onMethodInvoke(const QCefBrowserId& browserId,
                        const QCefFrameId& frameId,
                        const QString& method,
                        const QVariantList& arguments);
    void onCefQueryRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QCefQuery& query);
    void dispatch(const QString methodName,QVariantMap &args,QVariant &ret);
    void dispatch(const QString methodName,const QVariantList &args);
    void doCall(QObject *object, const QMetaMethod &metaMethod, QVariantList &args, QVariant &retVal);
    void reload(QString url);
    void loadCefView(QString url = "");
private:
    QWK::WidgetWindowAgent *windowAgent;
    Theme currentTheme{};
    QCefView *_cefWidget;
    QObjectList _queryServices;
    QWK::WindowButton *_setBtn;
    SettingsDialog *_setDlg;
    QWK::WindowBar *_windowBar;
};
#endif // MAINWINDOW_H
